export const remUnit = 75

import { WB_LISTS_CONTROL_ID } from '@/common/const-wb'
import { BG_POSITION_REPEAT_TYPES_MAP } from '@/common/const'

export function convertCss(cssStr) {
  return cssStr
  return cssStr.replace(/\d+px/g, function(a){
    let num = parseFloat(a).toFixed(0)
    let xx = parseInt(num % 2) + parseInt(num)
    let b =  xx / remUnit;
    return "string" == typeof a && a.match(/px$/) && (b += "vw"),b
  });
}
export function pxTovw(a) {
  return a
  let num = parseFloat(a).toFixed(0)
  //parseFloat((1 / i).toFixed(2)))
  let xx = parseInt(num % 2) + parseInt(num)
  let b =  xx / remUnit;
  return "string" == typeof a && a.match(/px$/) && (b += "vw"),b
}

export function getPxOrVw(){
  let unit = 'px'
  return unit
}

export function getPxOVwByValue(value){
  let unit = value + 'px'
  return unit
}

export function bgPositionStyle(styles_, bgPositionRepeatType){
  styles_.backgroundRepeat = 'no-repeat';
  if(bgPositionRepeatType == BG_POSITION_REPEAT_TYPES_MAP.centerTop){
    styles_.backgroundPosition = 'center top';
    styles_.backgroundSize = 'cover';
  }else if(bgPositionRepeatType == BG_POSITION_REPEAT_TYPES_MAP.contain){
    styles_.backgroundPosition = 'center top';
    styles_.backgroundSize = 'contain';
  }else if(bgPositionRepeatType == BG_POSITION_REPEAT_TYPES_MAP.width){
    styles_.backgroundPosition = 'center center';
    styles_.backgroundSize = '100% auto';
  }else if(bgPositionRepeatType == BG_POSITION_REPEAT_TYPES_MAP.centerBottom){
    styles_.backgroundPosition = 'center bottom';
    styles_.backgroundSize = 'contain';
  }else if(bgPositionRepeatType == BG_POSITION_REPEAT_TYPES_MAP.repeatY){
    styles_.backgroundPosition = 'center';
    styles_.backgroundRepeat = 'repeat';
    styles_.backgroundSize = 'contain';
  }else if(bgPositionRepeatType == BG_POSITION_REPEAT_TYPES_MAP.whole){
    styles_.backgroundPosition = 'center top';
    styles_.backgroundSize = '100% 100%';
  }
}

export function getMainEventControlId(events){
  let controlId = ''
  let tempArr = []
  _.forEach(events, (event) => {
    if(event.controlId && event.controlId.length > 0 && WB_LISTS_CONTROL_ID.indexOf(event.controlId) != -1){
      tempArr.push(event)
    }
  })
  if(tempArr.length > 0){
    tempArr = _.sortBy(tempArr, (event) => { return event.index; });
    controlId = tempArr[0].controlId
    //主事件是组件的第一个事件，是wblist值， controlId是组件的主事件id
  }
  return controlId
}

export function getMainListEventByEvents(events){
  let event
  let tempArr = []
  _.forEach(events, (event) => {
    if(event.controlId && event.controlId.length > 0 && WB_LISTS_CONTROL_ID.indexOf(event.controlId) != -1){
      tempArr.push(event)
    }
  })
  if(tempArr.length > 0){
    tempArr = _.sortBy(tempArr, (event) => { return event.index; });
    event = tempArr[0]
    //主事件是组件的第一个事件，是wblist值， controlId是组件的主事件id
  }
  return event
}

export function getMainWbDataEventByEvents(events){
  let event_
  let tempArr = []
  _.forEach(events, (event) => {
    if(event.controlId && event.controlId.length > 0){
      tempArr.push(event)
    }
  })
  if(tempArr.length > 0){
    tempArr = _.sortBy(tempArr, (event) => { return event.index; });
    event_ = tempArr[0]
    //主事件是组件的第一个事件，是wblist值， controlId是组件的主事件id
  }
  return event_
}

